<?php

namespace app\store\service;

use think\facade\Db;

class SpikeSessionService
{

    public function getSpikeSessionList($spike_meeting_id)
    {
        $spikeSessions =  Db::name('spike_session')->where('spike_meeting_id',$spike_meeting_id)
            ->withAttr('start_time',function($value){
                return date('Y-m-d H:i',$value);
            })->withAttr('end_time',function($value){
                return date('Y-m-d H:i',$value);
            })->paginate(['list_rows' => 10, 'id' => $spike_meeting_id]);
        
        return  $spikeSessions;   
    }

    public function getSpikeSessionGoods($spike_session_id)
    {

       $goods = Db::name('spike_goods')
                   ->alias('a')
                   ->field('b.id,c.id as spike_goods_id,c.goods_name,c.main_image,c.sell_price,a.spike_price,a.spike_stock,a.create_time')
                   ->join('spike_session_goods b','a.id=b.spike_goods_id')
                   ->join('goods c','a.goods_id=c.id')
                   ->where('b.spike_session_id',$spike_session_id)
                   ->paginate(['list_rows' => 10,'query' => ['spike_session_id' => $spike_session_id]]);



       return $goods;
    }


    public static function saveSpikeSessionGoods($data)
    {   
         

       $rows = Db::name('spike_session_goods')->insertAll($data);

       return $rows;
    }


    // 删除该场次的商品

    public static function deleteSpikeSessionGoods($id)
    {
        $rows = Db::name('spike_session_goods')->delete($id);
        
        return $rows;
    }
    
}